<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>专题管理</title>
		<%@ include file="../../common/Admin-list.jsp"%>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/gray/easyui.css"/>  
		<link rel="stylesheet" type="text/css" href="<%=basePath %>easyui/themes/icon.css"/>   
		<script type="text/javascript" src="<%=basePath %>JS/jquery/jquery-1.7.1.min.js"></script>     
		<script type="text/javascript" src="<%=basePath %>easyui/jquery.easyui.min.js"></script>
	
 		<script type="text/javascript">
			$(function(){
				$('#dataGridSys').datagrid({		
					height:'505',
					width:'100%',
					rownumbers:true,//设置为true将显示行数					
					striped:true, //设置为true将交替显示行背景
					fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
					animate:true,
					collapsible:true,
					idField:'id',//id字段
					pagination : true,//分页控件
					pageSize : 10,
				    pageList : [10, 20, 30],
				    url : '../subjectTopic/listData.json',
					loadMsg : '数据装载中......',
					singleSelect : true,//设置为 true，则只允许选中一行	
					toolbar: [{
						text: '添加',
						iconCls: 'icon-add',
						handler: function(){	
							art.dialog.open('../subjectTopic/addInterface.htm?type=add',{
										title: '',
										id:'addDialog',
										lock:true,
									  	width: '90%',
									    height: '90%'												   												   
									});
						}
					}, '-', {
		                text : '刷新',
		                iconCls : 'icon-reload',
		                handler : function() {
		                	$('#dataGridSys').datagrid('reload');
		                }
					}],	
					columns:[[					          	
								{field:'id',hidden:true,editor:{type:'text'}},
								{field:'title',title:'专题标题',width:100,align:'center',editor:{type:'text'}},
								{field:'summary',title:'简介',width:100,align:'center',editor:{type:'text'}},
								{field:'falg',title:'标识',width:100,align:'center',editor:{type:'text'}},
								{field:'is_publish',title:'是否已发布',width:100,align:'center',editor:{type:'text'},
								 formatter:function(value,rec,index){
									 if(value=='0')
										 {
										 return "未发布";
										 }
									 else
										 {
										 return "已发布";
										 }
								 }
								},								
								{field:'title_image',title:'专题图片',width:100,align:'center',editor:{type:'text'}},	
								{field:'template_title',title:'专题模版',width:100,align:'center',editor:{type:'text'}},	
								{field:'islink',title:'专题类型',width:100,align:'center',editor:{type:'text'},
									formatter:function(value,rec,index){
										if(value=='0')
											{
											return "外部专题";
											}
										else
											{
											return "内部专题";
											}
									}
								},	
								{field:'link_url',title:'专题链接路径',width:100,align:'center',editor:{type:'text'}},
								
								
								{field:'opt',title:'操作',width:50,align:'left',  
				                    formatter:function(value,rec,index){
				                    	
				                    	var edit='<a title="编辑" onclick="edit(\''+ rec.id + '\')"  href="#">'+
				                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;&nbsp;&nbsp;';
				                    	
				                        var dele='<a title="删除" onclick="del(\''+ rec.id +'\')"  href="#">'+
				                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                                          
				                      
				                        var auditState='';
							            if(rec.is_publish=='0')
							             {
								              auditState='<a title="发布" onclick="topic_publish(\''+ rec.id +'\')"  href="#">'+
							                     '<img src="<%=basePath %>pages/Admin/Images/Icon/audit.png" alt="发布"></a>&nbsp;&nbsp;';
							              }
							              else if(rec.is_publish=='1')
							             {
								               auditState='<a title="撤销发布" onclick="topic_unPublish(\''+ rec.id +'\')"  href="#">'+
							                        '<img src="<%=basePath %>pages/Admin/Images/Icon/unaudit.png" alt="撤销"></a>&nbsp;&nbsp;';
							             }		
				                        		
				                        return edit+dele+auditState;  
				                    }  
				                 }								
					        ]]	
				});	
			});
			
			
			function topic_publish(id)
			{
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定发布该专题？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../subjectTopic/topic_publish.json',
							data:{id:id},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('发布成功！');
									refresh();
								}else{
									art.dialog.alert('发布失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});		
			}
			
			
			
			
			function topic_unPublish(id)
			{
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定要撤销该发布该专题？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../subjectTopic/topic_unPublish.json',
							data:{id:id},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('撤销成功！');
									refresh();
								}else{
									art.dialog.alert('撤销失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});		
			}
			
			
			
			function edit(index){  //编辑   
				art.dialog.open('../subjectTopic/updateInterface.htm?type=edit&id='+index,{
					title: '',
					id:'editDialog',
					lock:true,
				  	width: '90%',
				    height: '90%'												   												   
				},function(){
					$('#dataGridSys').datagrid('reload');
				});
          	}
			
			function del(index){  //删除操作
				art.dialog({
					icon: 'question',	
					width:250,
				    content: '你确定删除该数据？',
				    ok: function () {				    	
				    	$.ajax({
							type:'POST',
							dataType:'json',
							async:false,
							url:'../subjectTopic/delete.json',
							data:{id:index,delSub:true},
							success:function(data){
								if(data.success=true){									
									art.dialog.alert('删除成功！');
									refresh();
								}else{
									art.dialog.alert('删除失败，请联系管理员！');
								}
							}
						});
				    },
				    cancelVal: '取消',
				    cancel: true 
				});				
          	}
		
			
			function refresh()
			{
				$('#dataGridSys').datagrid('reload');
			}
		</script>	
	</head>
	<body>
		<div>			
			<div id="tab">
        		<ul>
            		<li class="Current">
            			<a href="#"><span>专题管理</span></a>
            		</li>
            	</ul>
    		</div>

			<table id="dataGridSys"  style="width: 100%;"></table>
		</div>
	</body>
</html>